package cn.lanqiao.rabc.service.impl;

import cn.lanqiao.rabc.dao.UserDao;
import cn.lanqiao.rabc.dao.UserRoleDao;
import cn.lanqiao.rabc.entity.User;
import cn.lanqiao.rabc.service.UserService;
import cn.lanqiao.rabc.vo.QueryUserVO;
import cn.lanqiao.rabc.vo.UserVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;

    @Autowired
    UserRoleDao userRoleDao;

    @Override
    public List<UserVO> query(QueryUserVO queryUserVO) {
        return userDao.query(queryUserVO);
    }

    @Override
    public User queryByUserIdUser(int userId) {
        return userDao.selectById(userId);
    }

    @Transactional
    public void insert(UserVO userVO){
        userDao.insert(userVO);
        userRoleDao.insert(userVO);
    }

    public UserVO checkUser(UserVO user){
     return userDao.checkUser(user);
    }


    @Transactional
    public void update(UserVO userVO) {

    }

    @Override
    @Transactional
    public void delete(String ids) {
        //ids = 1,2,3,4 | ids = 1
        String[] idArray = ids.split(",");
//        for(String id : idArray){
//            userRoleDao.delete(id);
//        }
        userDao.deleteBatchIds(Arrays.asList(idArray));
    }
}
